package com.jiyun.behavior.service.ipl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.behavior.mapper.ApFollowBehaviorMapper;
import com.jiyun.behavior.service.ApFollowBehaviorService;
import com.usian.model.behavior.ApBehaviorEntry;
import com.usian.model.behavior.ApFollowBehavior;
import com.usian.model.behavior.FollowBehaviorDto;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ApFollowBehaviorServiceipl extends ServiceImpl<ApFollowBehaviorMapper, ApFollowBehavior> implements ApFollowBehaviorService {

    @Autowired
    ApBehaviorEntryServiceipl apBehaviorEntryServiceipl;

    @Autowired
    ApLikesBehaviorServiceipl apLikesBehaviorServiceipl;
//点赞列表的保存
    public ResponseResult saveFollowBehavior(FollowBehaviorDto dto){
//        先去查询设备信息
        ApBehaviorEntry apBehaviorEntry = apBehaviorEntryServiceipl.findbyUserIdOrEquipmentID(dto.getUserId(), null);
        if (apBehaviorEntry==null){
            return ResponseResult.errorResult(502,"实体不存在");
        }
//        创建中间表 用户和文章中间表
        ApFollowBehavior apFollowBehavior=new ApFollowBehavior();
        apFollowBehavior.setArticleId(dto.getArticleId());
        apFollowBehavior.setCreatedTime(new Date());
        apFollowBehavior.setEntryId(apBehaviorEntry.getId());
        apFollowBehavior.setFollowId(dto.getFollowId());
        save(apFollowBehavior);
//        添加中间表
        apLikesBehaviorServiceipl.dianzanxingwei(dto,apBehaviorEntry);
        return ResponseResult.okResult(200,"关注成功");

    }


}
